package com.hhp.hhptt.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhp.hhptt.entity.ImagesEntity;
import com.hhp.hhptt.mapper.ImagesMapper;
import com.hhp.hhptt.service.IImagesService;
import org.springframework.stereotype.Service;

@Service
public class IImagesServiceImpl extends ServiceImpl<ImagesMapper, ImagesEntity> implements IImagesService {
    @Override
    public boolean updateImagesBrowers(int id) {
        UpdateWrapper<ImagesEntity> updateWrapper = new UpdateWrapper<>();
        ImagesEntity imagesEntity = getById(id);
        int browse = imagesEntity.getBrowse();
        browse+=1;
        updateWrapper.eq("id", id).set("browse", browse);
        return update(updateWrapper);
    }

    @Override
    public boolean updateImagesLike(int id, Long uid, int status) {
        UpdateWrapper<ImagesEntity> updateWrapper = new UpdateWrapper<>();
        ImagesEntity imagesEntity = getById(id);
        int like = imagesEntity.getLike();
        //int like = imagesEntity.getBrowse();
        int isLike = imagesEntity.getIsLike();
        if (status==1){
            like+=1;
            if (isLike==1){
                updateWrapper.eq("id", id).set("`like`", like);
            }else {
                updateWrapper.eq("id", id).set("`like`", like).set("isLike",status);
            }

        }else {
            like-=1;
            updateWrapper.eq("id", id).set("`like`", like).set("isLike",status);
        }

        return update(updateWrapper);
    }
}
